home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Amiga Plus 2004 #11
/
Amiga Plus CD - 2004 - No. 11.iso
/
AmiSoft
/
Util
/
conv
/
SteBaseConv.lha
/
Convertitore
/
Convertitore.text
< prev
next >
Wrap
Text File
|
2004-08-29
|
15KB
|
612 lines
;***************************************************************************
;* *
;* Convertitore decimale, complemento a due, esadecimale, ottale e binario *
;* *
;***************************************************************************
;d> 20 aprile 2003 (Easter Day) from a Blitz2 Manual example
;m> 21 aprile 2003 (Angel Day)
;m> 26,27 aprile 2003
;m> 22,24 maggio 2003
;m> 8 giugno 2003
;m> 16 maggio 2004
;m> 30 giugno 2004
;m> 29 agosto 2004
;------------------
;the following lines of code are for correct program's version handling
JMP InizioDelProgramma
Dc .b "$VER: Convertitore 1.6 (29.8.2004)"
Even
InizioDelProgramma
;program start
#ListaBottoni=0
;gadgetlist identifier
;kind of gadget flags
#SoloDueValori=1
;toggle gadget
#LatoDestroFinestra=2
;window's right side related
#LatoBassoFinestra=4
;window's bottom side related
#LarghezzaFinestra=8
;window's width related
#AltezzaFinestra=16
;window's height related
#PiuDiDueValori=32
;more than two values
#MovimentoOrizzontale=64
;orizontal slider
#MovimentoVerticale=128
;vertical slider
#ProporzionaliSenzaBordo=256
;borderless slider
#SoloUnoTraTanti=512
;one from many
#AttaccaADestra=1024
;attach to window's right side
#AttaccaASinistra=2048
;attach to window's left side
#AttaccaInAlto=4096
;Attach to window's top side
#AttaccaInBasso=8192
;attach to window's bottom side
#BordoDammiZeroZero=16384
;gimme zero zero border
;gadget identifier
#CampoDiTestoDecimale=0
;decimal text field
#CampoDiTestoComplementoADue=1
;two complement text field
#CampoDiTestoEsadecimale=2
;hexadecimal text field
#CampoDiTestoOttale=3
;octal text field
#CampoDiTestoBinario=4
;binary text field
#FinestraConvertitore=0
;converter window identifier
#FinestraCrediti=1
;credits window identifier
;kind of window flags
#BottoneDimensionamentoFinestra=1
;window's sizing gadget
#SpostamentoFinestra=2
;draggable window
#ProfonditaFinestra=4
;window's depth gadget
#BottoneChiusuraFinestra=8
;window's close gadget
#BloccaDisegnoDestra=16
;clip right drawing
#BloccoDisegnoSotto=32
;clip bottom drawing
#FinestraComeSfondo=256
;backdrop window
#DammiZeroZero=1024
;gimme zero zero
#FinestraSenzaBordo=2048
;borderless window
#FinestraAttiva=4096
;window active
;window events
#HaiRidimensionatoLaFinestra=2
;you have resized the window
#LaFinestraECorrotta=4
;the window is corrupted
#HaiPremutoUnTastoDelTopo=8
;you have pressed a mouse button
#HaiMossoIlTopo=16
;you have moved the mouse
#HaiPremutoUnBottone=32
;you have pressed a gadget
#HaiRilasciatoUnBottone=64
;you have released a gadget
#HaiAttivatoIlMenu=256
;you have activated the menu
#HaiChiusoLaFinestra=512
;you have closed the window
#HaiPremutoUnTasto=1024
;you have pressed a key
#HaiInseritoUnDischetto=32768
;you have inserted a disk
#HaiToltoUnDischetto=65536
;you have removed a disk
#HaiAttivatoLaFinestra=262144
;you have activated the window
#HaiDisattivatoLaFinestra=524288
;you have deactivated the window
#ListaMenu=0
;menulist identifier
;kind of menu item flags
#VoceNormale=0
;normal item
#VoceSelettiva=1
;item with checkmark
#VoceSelettivaMultipla=2
;select one from two or more items
#VoceSelettivaSelezionata=3
;item selected
#VoceSelettivaMultiplaSelezionata=4
;one from two or more items selected
;menu settings
#Menu=0
;menu identifier
#VoceZero=0
;first menu item
#VoceUno=1
;second menu item
#VoceDue=2
;third menu item
;language selection
#Italiano=1
;italian
#Inglese=2
;english
#ValoreMassimo=16777215
;maximum value
;ascii values for used keys
#TabulationASCII=9
#LineFeedASCII=10
#CarriageReturnASCII=13
#EscapeASCII=27
#CursorUpASCII=28
#CursorDownASCII=29
#CursorRightASCII=30
#CursorLeftASCII=31
;workbench screen identifier number
#SchermoWB=0
#Cursore=1
;cursor lenght in chars
TastoTabulazione$=Chr$(#TabulationASCII)
;tabulation char
NuovaLinea$=Chr$(#LineFeedASCII)
;new line char
Invio$=Chr$(#CarriageReturnASCII)
;carriage return char
TastoEsc$=Chr$(#EscapeASCII)
;escape char
TastoCursoreSu$=Chr$(#CursorUpASCII)
;cursor up char
TastoCursoreGiu$=Chr$(#CursorDownASCII)
;cursor down char
TastoCursoreDestra$=Chr$(#CursorRightASCII)
;cursor right char
TastoCursoreSinistra$=Chr$(#CursorLeftASCII)
;cursor left char
DEFTYPE .b
Statement MostraLaBaseCorrente{Base}
SHARED AltezzaLineaBase
SHARED Lingua
Select Lingua
Case #Italiano
If Base=1 Then WColour 2,3
WLocate 1,1
Print "Decimale ":WColour 1,0
If Base=2 Then WColour 2,3
WLocate 1,1+AltezzaLineaBase+1
Print "Complemento":WColour 1,0
If Base=3 Then WColour 2,3
WLocate 1,1+(AltezzaLineaBase+1)*2
Print "Esadecimale":WColour 1,0
If Base=4 Then WColour 2,3
WLocate 1,1+(AltezzaLineaBase+1)*3
Print "Ottale ":WColour 1,0
If Base=5 Then WColour 2,3
WLocate 1,1+(AltezzaLineaBase+1)*4
Print "Binario ":WColour 1,0
Case #Inglese
If Base=1 Then WColour 2,3
WLocate 1,1
Print "Decimal ":WColour 1,0
If Base=2 Then WColour 2,3
WLocate 1,1+AltezzaLineaBase+1
Print "Complement ":WColour 1,0
If Base=3 Then WColour 2,3
WLocate 1,1+(AltezzaLineaBase+1)*2
Print "Hexadecimal":WColour 1,0
If Base=4 Then WColour 2,3
WLocate 1,1+(AltezzaLineaBase+1)*3
Print "Octal ":WColour 1,0
If Base=5 Then WColour 2,3
WLocate 1,1+(AltezzaLineaBase+1)*4
Print "Binary ":WColour 1,0
End Select
End Statement
Function $ ConvertiInOttale{ValoreDecimale.l}
Peso.l=1
If ValoreDecimale>=0
While Peso<#ValoreMassimo
CifraOttale$=Str$((ValoreDecimale/Peso) MOD 8)
ValoreOttale$=CifraOttale$+ValoreOttale$
Peso*8
Wend
Else
ValoreDecimale+1
While -Peso>-#ValoreMassimo-1
CifraOttale$=Str$(7-(-ValoreDecimale/Peso) MOD 8)
ValoreOttale$=CifraOttale$+ValoreOttale$
Peso*8
Wend
EndIf
Function Return ValoreOttale$
End Function
WBStartup
;the program can be executed from workbench
WbToScreen #SchermoWB
;workbench can be used as screen zero
AltezzaFonteFinestre=8
AltezzaFonteSchermo=8
OpenFontPrefs
AltezzaFonteSchermo=DefaultFontHeight(2)
AltezzaFonteFinestre=DefaultFontHeight(1)
CloseFontPrefs
;obtain the font height of screen and system fonts
AltezzaBarraTitoloWorkbench=AltezzaFonteSchermo+3
;workbench screenbar height
AltezzaCampoDiTesto=12
;text field height
AltezzaLineaBase=Max(AltezzaCampoDiTesto,AltezzaFonteFinestre)
;base line height
Select UCase$(ProgName$)
Case "CONVERTITORE"
Lingua=#Italiano
;italian language
Case "CONVERTER"
Lingua=#Inglese
;english language
Default
EZRequest "Converter request","You must rename the prog|Convertitore or Converter!","OK"
Goto FineDelProgramma
End Select
YPosBottone=1
XLunBottoni.w=8*25
YPosFinestra.w=AltezzaBarraTitoloWorkbench
YLunFinestra=AltezzaBarraTitoloWorkbench+1+(AltezzaLineaBase+1)*5+2
TipoFinestra.l=#SpostamentoFinestra+#ProfonditaFinestra+#BottoneChiusuraFinestra+#DammiZeroZero+#FinestraAttiva
Repeat
Select Lingua
Case #Italiano
XPosBottoni.w=1+Len("Esadecimale")*8+1
StringGadget #ListaBottoni,XPosBottoni,YPosBottone,0,#CampoDiTestoDecimale,8+#Cursore,XLunBottoni
YPosBottone+AltezzaLineaBase+1
StringGadget #ListaBottoni,XPosBottoni,YPosBottone,0,#CampoDiTestoComplementoADue,9+#Cursore,XLunBottoni
YPosBottone+AltezzaLineaBase+1
StringGadget #ListaBottoni,XPosBottoni,YPosBottone,0,#CampoDiTestoEsadecimale,6+#Cursore,XLunBottoni
YPosBottone+AltezzaLineaBase+1
StringGadget #ListaBottoni,XPosBottoni,YPosBottone,0,#CampoDiTestoOttale,8+#Cursore,XLunBottoni
YPosBottone+AltezzaLineaBase+1
StringGadget #ListaBottoni,XPosBottoni,YPosBottone,0,#CampoDiTestoBinario,24+#Cursore,XLunBottoni
MenuTitle #ListaMenu,#Menu,"Informazioni"
MenuItem #ListaMenu,#VoceNormale,#Menu,#VoceZero,"Crediti ","C"
MenuItem #ListaMenu,#VoceNormale,#Menu,#VoceUno, "English ","L"
MenuItem #ListaMenu,#VoceNormale,#Menu,#VoceDue, "Esci ","Q"
XLunFinestra.w=4+XPosBottoni+4+XLunBottoni+4+1+4
Window #FinestraConvertitore,0,YPosFinestra,XLunFinestra,YLunFinestra,TipoFinestra,"Convertitore Basi",1,2,#ListaBottoni
SetMenu #ListaMenu
MostraLaBaseCorrente{BottoneAttivo+1}
Case #Inglese
XPosBottoni=1+Len("Hexadecimal")*8+1
StringGadget #ListaBottoni,XPosBottoni,YPosBottone,0,#CampoDiTestoDecimale,8+#Cursore,XLunBottoni
YPosBottone+AltezzaLineaBase+1
StringGadget #ListaBottoni,XPosBottoni,YPosBottone,0,#CampoDiTestoComplementoADue,9+#Cursore,XLunBottoni
YPosBottone+AltezzaLineaBase+1
StringGadget #ListaBottoni,XPosBottoni,YPosBottone,0,#CampoDiTestoEsadecimale,6+#Cursore,XLunBottoni
YPosBottone+AltezzaLineaBase+1
StringGadget #ListaBottoni,XPosBottoni,YPosBottone,0,#CampoDiTestoOttale,7+#Cursore,XLunBottoni
YPosBottone+AltezzaLineaBase+1
StringGadget #ListaBottoni,XPosBottoni,YPosBottone,0,#CampoDiTestoBinario,24+#Cursore,XLunBottoni
MenuTitle #ListaMenu,#Menu,"Information"
MenuItem #ListaMenu,#VoceNormale,#Menu,#VoceZero,"Credits ","C"
MenuItem #ListaMenu,#VoceNormale,#Menu,#VoceUno,"Italiano ","L"
MenuItem #ListaMenu,#VoceNormale,#Menu,#VoceDue,"Quit ","Q"
XLunFinestra=4+1+XPosBottoni+1+4+XLunBottoni+4+1+4
Window #FinestraConvertitore,0,YPosFinestra,XLunFinestra,YLunFinestra,TipoFinestra,"Base Converter",1,2,#ListaBottoni
SetMenu #ListaMenu
MostraLaBaseCorrente{BottoneAttivo+1}
End Select
Repeat
EventoFinestra.l=WaitEvent
HaiPremutoUnBottone.l=EventoFinestra & %0000000000100000
If HaiPremutoUnBottone=#HaiPremutoUnBottone
;if text field selected
BottoneAttivo=GadgetHit
MostraLaBaseCorrente{BottoneAttivo+1}
EndIf
HaiRilasciatoUnBottone.l=EventoFinestra & %0000000001000000
If HaiRilasciatoUnBottone=#HaiRilasciatoUnBottone
;if text field selected and then Return pressed
BottoneAttivo=GadgetHit
Select BottoneAttivo
Case #CampoDiTestoDecimale
NuovoValore.l=Val(StringText$(#ListaBottoni,#CampoDiTestoDecimale))
If NuovoValore>-1 AND NuovoValore<16777216
Complemento.l=1
Repeat
Complemento*2
Until Complemento>=NuovoValore
Else
Pop If:Pop Select:Goto FineSelezioneCampo
EndIf
Case #CampoDiTestoComplementoADue
NuovoValore=Val(StringText$(#ListaBottoni,#CampoDiTestoComplementoADue))
If NuovoValore>-16777217 AND NuovoValore<0
Complemento=1
Repeat
Complemento*2
Until Complemento>=-NuovoValore
NuovoValore=-Complemento
Else
Pop If:Pop Select:Goto FineSelezioneCampo
EndIf
Case #CampoDiTestoEsadecimale
Valore$=UCase$(StringText$(#ListaBottoni,#CampoDiTestoEsadecimale))
NuovoValore=0
PosizioneStringa=Len(Valore$)
Peso.l=1
Complemento=0
While PosizioneStringa>0
Cifra=Asc(Mid$(Valore$,PosizioneStringa,1))
If Cifra>47 AND Cifra<58
Cifra-48
Else
If Cifra>64 AND Cifra<71
Cifra-55
Else
Pop If:Pop While:Pop Select:Goto FineSelezioneCampo
EndIf
EndIf
NuovoValore+Cifra*Peso
PosizioneStringa-1
Peso*16
Wend
If Cifra>0 Then Complemento=Peso
Case #CampoDiTestoOttale
Valore$=StringText$(#ListaBottoni,#CampoDiTestoOttale)
NuovoValore=0
PosizioneStringa=Len(Valore$)
Peso=1
Complemento=0
While PosizioneStringa>0
Cifra=Asc(Mid$(Valore$,PosizioneStringa,1))
If Cifra>47 AND Cifra<56
Cifra-48
Else
Pop If:Pop While:Pop Select:Goto FineSelezioneCampo
EndIf
NuovoValore+Cifra*Peso
PosizioneStringa-1
Peso*8
Wend
If Cifra>0 Then Complemento=Peso
Case #CampoDiTestoBinario
Valore$=StringText$(#ListaBottoni,#CampoDiTestoBinario)
NuovoValore=0
PosizioneStringa=Len(Valore$)
Peso=1
Complemento=0
While PosizioneStringa>0
Cifra=Asc(Mid$(Valore$,PosizioneStringa,1))
If Cifra>47 AND Cifra<50
Cifra-48
Else
Pop If:Pop While:Pop Select:Goto FineSelezioneCampo
EndIf
NuovoValore+Cifra*Peso
PosizioneStringa-1
Peso*2
Wend
If Cifra>0 Then Complemento=Peso
End Select
FineSelezioneCampo
If NuovoValore<>Valore.l
;if there is a new value
Valore=NuovoValore
SetString #ListaBottoni,#CampoDiTestoDecimale,Str$(Valore)
SetString #ListaBottoni,#CampoDiTestoComplementoADue,Str$(-Complemento)
SetString #ListaBottoni,#CampoDiTestoEsadecimale,Right$(Hex$(Valore),6)
SetString #ListaBottoni,#CampoDiTestoOttale,Right$(ConvertiInOttale{Valore},8)
SetString #ListaBottoni,#CampoDiTestoBinario,Right$(Bin$(Valore),24)
Redraw #FinestraConvertitore
EndIf
MostraLaBaseCorrente{BottoneAttivo+1}
EndIf
NuovaLingua=0
;new language
HaiAttivatoIlMenu.l=EventoFinestra & %0000000100000000
If HaiAttivatoIlMenu=#HaiAttivatoIlMenu
;if the menu has been activated
If MenuHit=#Menu
Select ItemHit
Case #VoceZero
Select Lingua
Case #Italiano
TitoloPannelloCrediti$="Crediti"
Crediti$="Convertitore Basi 1.4|"
Crediti$+"domenica, 16 maggio 2004|"
Crediti$+"di Stefano Maria Regattin|"
Crediti$+"dal manuale cartaceo|"
Crediti$+"di Blitz Basic 2.1"
Case #Inglese
TitoloPannelloCrediti$="Credits"
Crediti$="Base Converter 1.4|"
Crediti$+"Sunday, 16th May 2004|"
Crediti$+"by Stefano Maria Regattin|"
Crediti$+"from Blitz Basic 2.1|"
Crediti$+"paper manual"
End Select
EZRequest TitoloPannelloCrediti$,Crediti$,"OK"
;show the credits
Case #VoceUno
Select Lingua
Case #Italiano
NuovaLingua=#Inglese
Case #Inglese
NuovaLingua=#Italiano
End Select
;select the new language
Case #VoceDue
EsciDalProgramma=True
;exit from the program
End Select
EndIf
EndIf
If NuovaLingua>0 Then Lingua=NuovaLingua
HaiChiusoLaFinestra.l=EventoFinestra & %0000001000000000
If HaiChiusoLaFinestra=#HaiChiusoLaFinestra Then EsciDalProgramma=True
;if the window has been closed
HaiPremutoUnTasto.l=EventoFinestra & %0000010000000000
If HaiPremutoUnTasto=#HaiPremutoUnTasto
;if a key has been pressed
TastoPremuto$=Inkey$
Select TastoPremuto$
Case TastoTabulazione$
;tabulation char
BottoneAttivo+1:If BottoneAttivo=5 Then BottoneAttivo=0
MostraLaBaseCorrente{BottoneAttivo+1}
Case Invio$
;Return char
ActivateString #FinestraConvertitore,BottoneAttivo
Redraw #FinestraConvertitore
Case TastoCursoreSu$
;cursor up char
BottoneAttivo-1:If BottoneAttivo=-1 Then BottoneAttivo=4
MostraLaBaseCorrente{BottoneAttivo+1}
Case TastoCursoreGiu$
;cursor down char
BottoneAttivo+1:If BottoneAttivo=5 Then BottoneAttivo=0
MostraLaBaseCorrente{BottoneAttivo+1}
Case TastoCursoreDestra$
;cursor right char
BottoneAttivo+1:If BottoneAttivo=5 Then BottoneAttivo=0
MostraLaBaseCorrente{BottoneAttivo+1}
Case TastoCursoreSinistra$
;cursor left char
BottoneAttivo-1:If BottoneAttivo=-1 Then BottoneAttivo=4
MostraLaBaseCorrente{BottoneAttivo+1}
Case TastoEsc$
;escape char
EsciDalProgramma=True
End Select
EndIf
Until EsciDalProgramma=True OR NuovaLingua>0
CloseWindow #FinestraConvertitore
Until EsciDalProgramma=True
FineDelProgramma
End